package com.terry.mars_xlog;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Environment;
import android.view.View;

import com.tencent.mars.xlog.Log;
import com.tencent.mars.xlog.Xlog;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        System.loadLibrary("c++_shared");
        System.loadLibrary("marsxlog");


        final String SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath();
        final String logPath = SDCARD + "/marssample/log";

        // this is necessary, or may crash for SIGBUS
        final String cachePath = this.getFilesDir() + "/xlog";

        //init xlog
        if (BuildConfig.DEBUG) {
            Xlog.appenderOpen(Xlog.LEVEL_DEBUG, Xlog.AppednerModeSync, cachePath, logPath, "MarsSample", 0, "");
            Xlog.setConsoleLogOpen(true);
        } else {
            Xlog.appenderOpen(Xlog.LEVEL_INFO, Xlog.AppednerModeAsync, cachePath, logPath, "MarsSample", 0, "");
            Xlog.setConsoleLogOpen(false);
        }

        Log.setLogImp(new Xlog());







    }

    public void onButtonClick(View view){
        Log.d("Terry","xxxxxxxx");

        for (int i = 100; i > 0; i--) {
            Log.d("Terry","xxxx "+i+" xxxx");
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.appenderClose();
    }
}
